<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
$no		= $HTTP_GET_VARS['no'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM VSanksi WHERE NIK='$nik' ) SELECT * FROM limit WHERE No='$no'",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
?>
<script type="text/javascript">
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){

		if(document.forms[0].nik.value == ""){
			alert("Maaf, NIK tidak boleh kosong ...");
			document.forms[0].nik.focus();
			return false;
		}

		if(document.forms[0].no_surat.value == ""){
			alert("Maaf, Nomor Surat tidak boleh kosong ...");
			document.forms[0].no_surat.focus();
			return false;
		}
		
		if(document.forms[0].tgl_berlaku.value == ""){
			alert("Maaf, Tanggal Berlaku tidak boleh kosong ...");
			document.forms[0].tgl_berlaku.focus();
			return false;
		}
		
		if(document.forms[0].tgl_keluar.value == ""){
			alert("Maaf, Tanggal Keluar tidak boleh kosong ...");
			document.forms[0].tgl_keluar.focus();
			return false;
		}

		if(document.forms[0].katsanksi.value == ""){
			alert("Maaf, Kategori Sanksi tidak boleh kosong ...");
			document.forms[0].katsanksi.focus();
			return false;
		}

		if(document.forms[0].sanksi.value == ""){
			alert("Maaf, Sanksi tidak boleh kosong ...");
			document.forms[0].sanksi.focus();
			return false;
		}
		/*
		if(document.forms[0].lokasi.value == ""){
			alert("Maaf, Lokasi tidak boleh kosong ...");
			document.forms[0].lokasi.focus();
			return false;
		}

		if(document.forms[0].seksi.value == ""){
			alert("Maaf, Seksi tidak boleh kosong ...");
			document.forms[0].seksi.focus();
			return false;
		}

		if(document.forms[0].seksi.value == ""){
			alert("Maaf, Seksi tidak boleh kosong ...");
			document.forms[0].seksi.focus();
			return false;
		}
		
		if(document.forms[0].info_detail.value == ""){
			alert("Maaf, Informasi Detail tidak boleh kosong ...");
			document.forms[0].info_detail.focus();
			return false;
		}
		
		if(document.forms[0].fungsi.value == ""){
			alert("Maaf, Kelompok Fungsional tidak boleh kosong ...");
			document.forms[0].fungsi.focus();
			return false;
		}
				
		if(document.forms[0].nama_jabatan.value == ""){
			alert("Maaf, Nama Jabatan tidak boleh kosong ...");
			document.forms[0].nama_jabatan.focus();
			return false;
		}

		if(document.forms[0].golongan.value == ""){
			alert("Maaf, Golongan tidak boleh kosong ...");
			document.forms[0].golongan.focus();
			return false;
		}

		if(document.forms[0].status_karyawan.value == ""){
			alert("Maaf, Status Karyawan tidak boleh kosong ...");
			document.forms[0].status_karyawan.focus();
			return false;
		}

*/
		document.forms[0].submit();
	}
	
	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
	
	function rref(){
		var NIK  = document.getElementById("nik").value;//.value;
		var Nama  = document.getElementById("nama").value;//.value;
		
		//if(NIK == ""){
			//alert("Kososng");
		//}
//		alert(""+ NIK +"");
		top.location.href = "frm_emp_sanksi.php?nik="+ NIK +"&nama="+ Nama +"";
	}

</script>
</head>
   <table width="100%" class="table_indent2" border="0">
    <tr>
	 <td class="line_bottom">&nbsp;&nbsp;<b>SANKSI</b></td>
	</tr>
   </table>
<form method="post" action="<?=$Faction?>">
<table width="100%" border="0">
 <tr>
  <td colspan="5">
   <table border="0">
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik" value="<?=$nik?>" readonly="" id="nik" />
	<?
		//if($HTTP_GET_VARS['nik'] == NULL ){
		if($op == NULL){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input value="<?
     if(empty($HTTP_GET_VARS['nama'])){
	 	echo $row[Nama];
	 }
	 else{
	 	echo $HTTP_GET_VARS['nama'];
	 }
	 ?>" readonly="readonly" id="nama" type="text" name="nama" size="45" /></td>
	</tr>	
   </table>
  </td>
 </tr>
 <tr>
  <td colspan="5"><hr noshade="noshade" size="-2"/></td>
 </tr>
 <tr>
  <td valign="top" colspan="3" width="50%">
  <fieldset><legend>SURAT KEPUTUSAN - SANKSI KARYAWAN</legend>
  <table border="0">
 <tr>
  <td width="100">No. Surat</td>
  <td><input type="text" name="no_surat" size="35" value="<?=$row[no_surat]?>" /> <span class="required">*</span>
</td>
 </tr>
 <tr>
  <td>Tanggal Berlaku</td>
  <td><input type="text" maxlength="10" size="11" value="<?=$row[TglBerlaku]?>" name="tgl_berlaku" /> <a href="javascript:calA.popup();"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Tanggal Keluar</td>
  <td><input type="text" maxlength="10" size="11" value="<?=$row[TglKeluar]?>" name="tgl_keluar" /> <a href="javascript:calB.popup();"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Kalendar" title="Kalendar"></a> <span class="required">*</span></td>
 </tr>
 <tr>
  <td>Kategori Sanksi:</td>
  <td>
   <select name="katsanksi">
    <option value="">--pilih--</option>
    <?
    	$qS = mssql_query("SELECT * FROM VKatSanksi ORDER BY nama ASC");
		while($rS = mssql_fetch_array($qS)){
			echo"<option value='$rS[kode]'";
			if($rS[kode] == $row[category]){
				echo"selected";
			}
			echo">$rS[nama]</option>";
		}
	?>
   </select> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td colspan="2">
  Sanksi:<br />
  <textarea cols="45" rows="7" name="sanksi"><?=$row[sanksi]?></textarea> <span class="required">*</span>
  </td>
 </tr>
 <tr>
  <td colspan="2">
  Keterangan:<br />
  <textarea cols="45" rows="7" name="keterangan"><?=$row[keterangan]?></textarea>
  </td>
 </tr>
 </table>
 </fieldset>
  </td>
  <td valign="top" width="50%">
  <fieldset><legend>Histori Sanksi Karyawan</legend>
  <?
  	if($op == ""){
  ?>
  <input type="button" value="Refresh" onclick="Javascript:rref();" class="button"/>
  <?
  }
  else{
  }
  ?>
   <table border="0" width="100%">
   <tr class="headlist">
    <td width="1%">No.</td>
	<td>No. Surat</td>
	<td>Tanggal Berlaku</td>
	<td>Tanggal Keluar</td>
    <td>Kategori <br />Sanksi</td>
	<td>Sanksi</td>
	<td>Keterangan</td>
   </tr>
<?
$sqls	= mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM VSanksi WHERE NIK='$nik' ORDER BY No ASC ",$conn);
if(mssql_num_rows($sqls) > 0)
{
while($rows = mssql_fetch_array($sqls)){
	echo"
	<tr class=contentlist>
	 <td align=right><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$rows[No]'>$rows[No]</a></td>
	 <td><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$rows[No]'>$rows[no_surat]</a></td>
	 <td align=right><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$rows[No]'>$rows[TglBerlaku]</a></td>
	 <td align=right><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$rows[No]'>$rows[TglKeluar]</a></td>	 ";
	 $gks = mssql_query("SELECT nama FROM VKatSanksi WHERE kode='$rows[category]'",$conn);
	 $rks = mssql_fetch_array($gks);
	 echo"<td>$rks[nama]</td>";
	 echo"<td><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$rows[No]'>$rows[sanksi]</a></td>
	 <td><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$rows[No]'>$rows[keterangan]</a></td>
	 ";
	 
/*	 $slokasi = mssql_query("SELECT * FROM MstLokasi WHERE kode_lokasi='$row[lokasi]'",$conn);
	 $rlokasi = mssql_fetch_array($slokasi);
	 echo"$rlokasi[distrik] - $rlokasi[propinsi]";
	 echo"</a></td>	 
	 <td><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$row[No]'>";
	 $sUK = mssql_query("SELECT * FROM MstSO WHERE kode_so='$row[kode_so]'",$conn);
	 $rUK = mssql_fetch_array($sUK);
	 echo"$rUK[uraian]";
	 echo"</a></td>	 
	 <td><a href='../lib/show.php?show=detail_sanksi&amp;nik=$nik&amp;no=$row[No]'>$row[jabatan]</a></td>	 
	</tr>
	";
*/
	}
}
else{
	echo"
	 <tr>
	  <td colspan=6 align=center> -- Untuk menampilkan klik tombol REFRESH setelah memasukkkan NIK pegawai --</td>
	 </tr>
	";
}
?>
   </table>
   </fieldset>
  </td>
 </tr>
 <tr>
  <td align="left" colspan="4">
  <input type="hidden" name="cat" value="sanksi" />
  <input type="hidden" name="no" value="<?=$row[No]?>" />
  <input type="button" value="Batal" class="button" onclick="Javascript:history.back();" />
  <input type="button" value="<?=$Vbutton?>" class="button" onclick="Javascript:Validate();" />
  </td>
 </tr>
</table>
</form>
</td>
</tr>
<tr>
 <td colspan="3" style="border:none;"><? include("../footer.php"); ?></td>
</tr>
</table>
</body>
<script type="text/javascript">

var f = document.forms[0];
MaskInput(f.tgl_berlaku,"99/99/9999");
MaskInput(f.tgl_keluar,"99/99/9999");
//]]>
</script>
<script type="text/javascript">
// script untuk popup calendar
	var calA = new calendar1(document.forms[0].elements['tgl_berlaku']);
	calA.year_scroll = true;
	calA.time_comp = false;	
	var calB = new calendar1(document.forms[0].elements['tgl_keluar']);
	calB.year_scroll = true;
	calB.time_comp = false;	
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>